home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / rep_man.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  9KB  |  304 lines

  1. #include <stdlib.h>
  2. #include "rep_man.h"
  3. #include <dos.h>
  4. #include <conio.h>
  5.  
  6. int ReportManager::draw_addinfo(ADDINFO_LAYOUT* info)
  7.     {
  8.     int height = 0;
  9.     char buf[20];
  10.     int p = info->pos.X + curr_pos.X;
  11.     switch(info->info_type)
  12.     {
  13.     case PCX_INFO:
  14.         textPage->draw_bar(rect(info->pos.X + curr_pos.X,
  15.         info->pos.Y + curr_pos.Y,
  16.         info->pos.X + info->service[0] + curr_pos.X,
  17.         info->pos.Y + info->service[1] + curr_pos.Y));
  18.         height += info->service[1];
  19.         break;
  20.     case TEXT_INFO:
  21.         height += textPage->putText(info->pos + curr_pos, info->str);
  22.         break;
  23.         case DATE_INFO:
  24.             struct date d;
  25.             getdate(&d);
  26.             switch(info->service[5])
  27.                 {
  28.                 case 1:       // day
  29.                     itoa(d.da_day, buf, 10);
  30.                     break;
  31.                 case 2:       // month
  32.                     itoa(d.da_mon, buf, 10);
  33.                     break;
  34.                 case 3:       // year
  35.                     itoa(d.da_year, buf, 10);
  36.                     break;
  37.                 case 0:       // date
  38.                 default:
  39.                     int len;
  40.                     itoa(d.da_day, buf, 10);
  41.                     len = strlen(buf);
  42.                     buf[len] = '.';
  43.                     itoa(d.da_mon, buf + len + 1, 10);
  44.                     len = strlen(buf);
  45.                     buf[len] = '.';
  46.                     itoa(d.da_year, buf + len + 1, 10);
  47.                     break;
  48.                 }
  49.             textPage->putText(info->pos + curr_pos, buf);
  50.             break;
  51.     case PAGE_INFO:
  52.             itoa(page_number, buf, 10);
  53.             textPage->putText(info->pos + curr_pos, buf);
  54.             break;
  55.     case REC_NO_INFO:
  56.             ltoa(record_number, buf, 10);
  57.             textPage->putText(info->pos + curr_pos, buf);
  58.             break;
  59.     }
  60.     return height;
  61.     }
  62. ///////////////////////////////
  63. int ReportManager::print_add(ADD_LIST* band, loc xy)
  64.     {
  65.     int height = 0;
  66.     if(band != NULL)
  67.     {
  68.     curr_pos = xy;
  69.     for(int i = 0; i < band->used_add; i++)
  70.         height += draw_addinfo(band->add_list[i]);
  71.     }
  72.     return height;
  73.     }
  74. ///////////////////////////////
  75. int ReportManager::print_record(int stop_printing)
  76.     {
  77.     if(stop_printing)
  78.         if(curr_pos.Y >= page->table_band_bottom)
  79.         return 1;
  80.     else
  81.         if(curr_pos.Y >= page->page_band_bottom)
  82.         return 1;
  83.  
  84.     curr_pos.Y += print_add(page->rc_top_info, curr_pos);
  85.  
  86.     int height = print_add(page->record, curr_pos);        // Record add info
  87.  
  88.     uchar* buf = new uchar[255];
  89.     for(int i = 0; i < page->record->used_fields; i++)
  90.     {
  91.     table->setFld(page->record->field_list[i]->fieldNumber);
  92.     KH_FIELD_TYPE type = table->TranslateField(buf);
  93.     if(type != KH_BLOB)
  94.         {
  95.         int h = textPage->putText(
  96.         loc(curr_pos.X + page->record->field_list[i]->coord.origin.X,
  97.             curr_pos.Y + page->record->field_list[i]->coord.origin.Y),
  98.             buf);
  99.         height = max(height,
  100.              (labels_format & SKIP_WHITE)
  101.              ? h + page->record->field_list[i]->coord.origin.Y
  102.              : page->record->field_list[i]->coord.corner.Y);
  103.         }
  104.     else
  105.         {
  106.         // To be modified to work with pictures of different types
  107.         }
  108.     }
  109.     delete buf;
  110.  
  111.     curr_pos.Y += height;
  112.     height = print_add(page->rc_bottom_info, curr_pos);
  113.     curr_pos.Y += height;
  114.  
  115.     if(curr_pos.Y >= page->page_band_bottom)
  116.     return 1;
  117.     return 0;
  118.     }
  119. ///////////////////////////////
  120. int ReportManager::buildPage(int table_beginning)
  121.     {
  122.     int stop_printing = 0;          // Not at the end of table
  123.     int end_of_page = 0;            // EOP while printing recorgs (rec. band)
  124.  
  125.     if(quality != DRAFT)            // To be modified in next version
  126.     return 1;
  127.     int curr_col = 1;
  128.     curr_pos = loc(0, 0);
  129.     while(!end_of_page && !stop_printing)         // Page printing cycle
  130.     {
  131.     print_add(page->pg_top_info, loc(0, page->page_band_top));
  132.  
  133.     if(table_beginning)
  134.         print_add(page->tb_top_info, loc(0, page->table_band_top));
  135.  
  136.     int res_pos = curr_pos.Y = /*curr_pos.Y + */page->record_band_top;
  137.     loc reserv_pos = curr_pos;
  138.     while(!end_of_page && !stop_printing)         // Record printing cycle
  139.         {
  140.         pxErr = PXRecGet(table->tblHandle, table->recHandle);
  141.             pxErr = PXRecNum(table->tblHandle, &record_number);
  142.             if((pxErr = PXRecNext(table->tblHandle)) != PXSUCCESS)
  143.         stop_printing = 1;
  144.  
  145.         end_of_page = print_record(stop_printing);          // Not at the end of table);
  146.  
  147.         if(end_of_page && curr_col < num_of_col)
  148.         {
  149.         end_of_page = 0;
  150.         curr_col++;
  151.         curr_pos.X += PAGE_WIDTH / num_of_col;
  152.         curr_pos.Y = res_pos;
  153.         }
  154.         }
  155.     if(stop_printing)
  156.         print_add(page->tb_bottom_info, loc(0, curr_pos.Y));//page->table_band_bottom));
  157.     print_add(page->pg_bottom_info, loc(0, page->page_band_bottom));
  158.     page_number++;
  159.     }
  160.     return stop_printing;
  161.     }
  162. ///////////////////////////////
  163. void ReportManager::print()
  164.     {
  165.     pxErr = PXRecFirst(table->tblHandle);          // Dummy reposition
  166.     int table_beginning = 1;
  167.     while(1)         // Page-by-page printing
  168.     {
  169.     if(kbhit())
  170.         {
  171.         getch();
  172.         if(exit_func())
  173.         break;
  174.         }
  175.  
  176.     textPage->draw_bar(rect(0, 0, PAGE_WIDTH - 1, PAGE_HEIGHT - 1), ' ');
  177.     int stop_printing = buildPage(table_beginning);
  178.     table_beginning = 0;
  179.     curr_pos = loc(0, 0);
  180.     print_page();
  181.     if(stop_printing)
  182.         break;
  183.     }
  184.     }
  185. ///////////////////////////////
  186. void ReportManager::print_page()
  187.     {
  188.     if(quality != DRAFT)
  189.     return;
  190.     char* txt;
  191.     for(int i = 0; i < PAGE_HEIGHT; i++)
  192.     {
  193.     fputs(txt = textPage->page[i], stdprn);
  194.     fputs("\r\n", stdprn);
  195.     }
  196.     fputc(12, stdprn);
  197.     }
  198. //////////////////////////////
  199. /*
  200. void main()
  201.     {
  202.     if(PXInit() != PXSUCCESS)
  203.     return;
  204.  
  205.     KH_PXTable* table = new KH_PXTable("demo.db");
  206.  
  207.     ADDINFO_LAYOUT* add1 = new ADDINFO_LAYOUT(loc(10, 1), TEXT_INFO,
  208.     "PAGE TOP INFORMATION\nOF TEXT TYPE");
  209.     ADDINFO_LAYOUT* add2 = new ADDINFO_LAYOUT(loc(40, 1), PCX_INFO,
  210.     "demo1.pcx", 5, 3);
  211.  
  212.     ADD_LIST* p_top_info = new ADD_LIST();
  213.     p_top_info->add(add1, 0);
  214.     p_top_info->add(add2, 1);
  215.  
  216.     ADDINFO_LAYOUT* add3 = new ADDINFO_LAYOUT(loc(10, 1), TEXT_INFO,
  217.     "PAGE BOTTOM INFORMATION\nOF TEXT TYPE");
  218.     ADDINFO_LAYOUT* add4 = new ADDINFO_LAYOUT(loc(40, 1), PCX_INFO,
  219.     "demo2.pcx", 5, 3);
  220.  
  221.     ADD_LIST* p_bottom_info = new ADD_LIST();
  222.     p_bottom_info->add(add3, 0);
  223.     p_bottom_info->add(add4, 1);
  224.  
  225.     ADDINFO_LAYOUT* add5 = new ADDINFO_LAYOUT(loc(12, 1), TEXT_INFO,
  226.     "TABLE TOP INFORMATION\nOF TEXT TYPE");
  227.     ADDINFO_LAYOUT* add6 = new ADDINFO_LAYOUT(loc(1, 1), PCX_INFO,
  228.     "demo3.pcx", 5, 3);
  229.  
  230.     ADD_LIST* t_top_info = new ADD_LIST();
  231.     t_top_info->add(add5, 0);
  232.     t_top_info->add(add6, 1);
  233.  
  234.     ADDINFO_LAYOUT* add7 = new ADDINFO_LAYOUT(loc(12, 1), TEXT_INFO,
  235.     "TABLE BOTTOM INFORMATION\nOF TEXT TYPE");
  236.     ADDINFO_LAYOUT* add8 = new ADDINFO_LAYOUT(loc(1, 1), PCX_INFO,
  237.     "demo4.pcx", 5, 3);
  238.  
  239.     ADD_LIST* t_bottom_info = new ADD_LIST();
  240.     t_bottom_info->add(add7, 0);
  241.     t_bottom_info->add(add8, 1);
  242.  
  243.     ADDINFO_LAYOUT* add9 = new ADDINFO_LAYOUT(loc(12, 1), TEXT_INFO,
  244.     "RECORD TOP INFORMATION\nOF TEXT TYPE");
  245.     ADDINFO_LAYOUT* add10 = new ADDINFO_LAYOUT(loc(1, 1), PCX_INFO,
  246.     "demo5.pcx", 5, 3);
  247.  
  248.     ADD_LIST* r_top_info = new ADD_LIST();
  249.     r_top_info->add(add9, 0);
  250.     r_top_info->add(add10, 1);
  251.  
  252.     ADDINFO_LAYOUT* add11 = new ADDINFO_LAYOUT(loc(12, 1), TEXT_INFO,
  253.     "RECORD BOTTOM INFORMATION\nOF TEXT TYPE");
  254.     ADDINFO_LAYOUT* add12 = new ADDINFO_LAYOUT(loc(1, 1), PCX_INFO,
  255.     "demo6.pcx", 5, 3);
  256.  
  257.     ADD_LIST* r_bottom_info = new ADD_LIST();
  258.     r_bottom_info->add(add11, 0);
  259.     r_bottom_info->add(add12, 1);
  260.  
  261.     ADDINFO_LAYOUT* add13 = new ADDINFO_LAYOUT(loc(7, 0), TEXT_INFO,
  262.     "FIELD 1:                             FIELD 2:\n\
  263. FIELD 3:                             FIELD 4:");
  264.     FIELD_LAYOUT* fld1 = new FIELD_LAYOUT(rect(15, 0, 44, 1), 1);
  265.     FIELD_LAYOUT* fld2 = new FIELD_LAYOUT(rect(54, 0, 80, 2), 2);
  266.     FIELD_LAYOUT* fld3 = new FIELD_LAYOUT(rect(15, 1, 44, 2), 3);
  267.     FIELD_LAYOUT* fld4 = new FIELD_LAYOUT(rect(54, 1, 80, 2), 4);
  268.  
  269.     RECORD_LAYOUT* rec = new RECORD_LAYOUT();
  270.     rec->ADD_LIST::add(add13, 0);
  271.     rec->FIELD_LIST::add(fld1, 0);
  272.     rec->FIELD_LIST::add(fld2, 1);
  273.     rec->FIELD_LIST::add(fld3, 2);
  274.     rec->FIELD_LIST::add(fld4, 3);
  275.  
  276.     PAGE_LAYOUT* page = new PAGE_LAYOUT(
  277.     0,  // p_band_top
  278.     56, // p_band_bottom,
  279.     5,  // t_band_top,
  280.     50, // t_band_bottom*,
  281.     10, // r_band_top,
  282.     45, // r_band_bottom,
  283.     p_top_info, p_bottom_info, t_top_info, t_bottom_info, r_top_info,
  284.     r_bottom_info, rec);
  285.  
  286.     ReportManager* report = new ReportManager(page, table, DRAFT,
  287.     LABELS_AS_IS); // l_format
  288.  
  289.     report->print();
  290.  
  291.     delete table;
  292.     delete p_top_info;
  293.     delete p_bottom_info;
  294.     delete t_top_info;
  295.     delete t_bottom_info;
  296.     delete r_top_info;
  297.     delete r_bottom_info;
  298.     delete rec;
  299.     delete page;
  300.     delete report;
  301.  
  302.     PXExit();
  303.     }
  304. */